(function () {
	 /**
	 * 异步json获取
	 * @param {String} url 接口地址
	 * @param {Object} param 发送数据
	 * @param {Function} [success] 成功回调
	 * @param {Function} [error] 错误回调
	 */
var $modal = $('#pop-modal');
	 getPageData({});
	 function getPageData (Filter)
	 {
	 	var Filter = Filter;
	 		Filter.page = page.page;
	 		Filter.pageSize = page.pageSize;
	 	getJson(Domain+'/ec/usedSeek/doSearchUsedSeekList.do', Filter, function (res) {
		  if(!res.success){
	
		    $('.am-modal-bd').text(res.errorMessage);
				$modal.modal();
				setTimeout(function () {
					$modal.modal('close');
				},iWiating);

		  }
		  else{

	  	 	 $('#totalnum').text(res.data.rowCount);	

	  		  page.nowPage = res.data.pageId;
      		  page.pageCount = res.data.pageCount;
      		  
      		  if(!res.data.rows.length){
		        $('.am-pagination').remove();
		        $('#itemlist').append('<li class="empty_div">没有相关的商品哦~</li>');
		        return
		      }

		     $('#itemlist').empty();

			 renderTmp('#itemlist', 'itemlisttpl',res);

			 	lazyLoad.refresh(true);
			 	$('.am-pagination').createPage({
			        current: page.page,
			        type: 1,
			        pageCount: page.pageCount,
			        center: 3,
			        showLen: 11,
		        callback: function (curidx, obj) {
		          page.page = curidx;
		          $('#itemlist').empty();
		          getPageData(Filter);
		        }
		       });

			 	$('.textpage').createPage({
			        current: page.page,
			        type: 2,
			        pageCount: page.pageCount,
		        callback: function (curidx, obj) {
		          page.page = curidx;
		          $('#itemlist').empty();
		          getPageData(Filter);
		        }
		       });
		  }
		})
	 }

	 //期望价格排序
	 $('.normal').on('click',function () {

	 	getPageData({});

	 	activeOrder ($(this));

	 })

	 //期望历程排序
	 $('.orderdistance').on('click',function () {

	 
	 		getPageData({
	 			sort:'ml'
			});
	 	
	 	

	 	activeOrder ($(this));

	 });

	 //发布时间排序
	 $('.orderdate').on('click',function () {

	
	 		getPageData({
	    		sort:'pb'
			});
	 	
	 	

	 	activeOrder ($(this));

	 });

	 //人气排序
	 $('.orderpeople').on('click',function () {

	 
	 		getPageData({
	    		sort:'ht'
			});
	 	
	 	activeOrder ($(this));

	 });

	 //排序样式激活
	 function activeOrder (obj)
	 {
	 	$('.sort').find('span').not('.title').removeClass('active');
	 	$(obj).addClass('active');
	 }


	 //打开详情页
	 $('#itemlist').delegate('tr','click',function () {

	 	var iqgId = $(this).attr('data-id');

	 	toNewPage(oFilename.qgDetail+'?id='+iqgId,true);

	 });

})();